package com.ebelter.seneo.ui.fragments.infos;


import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.TextView;

import com.ebelter.btcomlib.common.IOrder;
import com.ebelter.btcomlib.models.db.products.seneo.SeneoUserCurrentMeasureRecord;
import com.ebelter.btcomlib.models.db.products.seneo.SeneoUserinfos;
import com.ebelter.btcomlib.models.eventbus.CommonEventBus;
import com.ebelter.btcomlib.utils.NumUtils;
import com.ebelter.btcomlib.utils.StringUtils;
import com.ebelter.btcomlib.utils.ViewUtils;
import com.ebelter.btcomlib.utils.log.LogUtils;
import com.ebelter.seneo.R;
import com.ebelter.seneo.contants.IUserContant;
import com.ebelter.seneo.models.SeneoBTManager;
import com.ebelter.seneo.ui.activitys.SeneoMainActivity;
import com.ebelter.seneo.ui.fragments.BaseFragment;
import com.ebelter.seneo.ui.fragments.main.Info_Fragment;
import com.ebelter.seneo.ui.views.LevelView;
import com.ebelter.seneo.utils.BodyCompositionCriteria;
import com.ebelter.seneo.utils.SeneoUtils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;


//填写密码
public class Info_Weight_Fragment extends BaseFragment implements Info_Fragment.IInfoUpdateInterface{


    public static final String TAG = "Info_Weight_Fragment";
    TextView infofly_value_tv;
    TextView infofly_valueunit_tv;
    TextView infofly_tip1_tv;
    LevelView info_levelview;

    final int[] colors = new int[]{
            Color.parseColor("#49D8F1"),
            Color.parseColor("#54BF4B"),
            Color.parseColor("#EFB847"),
            Color.parseColor("#EE7D65"),
    };
    String[] buttoms=new String[]{
            StringUtils.getResStr(R.string.piandi),
            StringUtils.getResStr(R.string.baiozhun),
            StringUtils.getResStr(R.string.piangao),
            StringUtils.getResStr(R.string.chaozhong)};

    float[] middleKg = new float[]{53.5f,66.5f,72.2f};
    float[] middleLb = new float[]{53.5f,66.5f,72.2f};

    private void dealMiddleValue(SeneoUserinfos currentUserinfos) {
        int height = currentUserinfos.height;
        middleKg[0]= BodyCompositionCriteria.getWeightKgByBMI(18.5f,height);//根据BMI得出临界值
        middleKg[1]= BodyCompositionCriteria.getWeightKgByBMI(24f,height);
        middleKg[2]= BodyCompositionCriteria.getWeightKgByBMI(28f,height);

        middleLb[0]=NumUtils.numBaoLiuWei1(SeneoUtils.kg2lb(middleKg[0]));
        middleLb[1]=NumUtils.numBaoLiuWei1(SeneoUtils.kg2lb(middleKg[1]));
        middleLb[2]=NumUtils.numBaoLiuWei1(SeneoUtils.kg2lb(middleKg[2]));
    }

    @Override
    protected int setLayoutResouceId() {
        return R.layout.info_fly1;
    }

    @Override
    protected void initView() {
        FV();
    }

    private void FV() {
        infofly_value_tv=findViewById(R.id.infofly_value_tv);
        infofly_valueunit_tv=findViewById(R.id.infofly_valueunit_tv);
        infofly_tip1_tv=findViewById(R.id.infofly_tip1_tv);
        info_levelview=findViewById(R.id.info_levelview);
    }


    @Override
    protected void initData(Bundle arguments) {
        //String tip=getString(R.string.str_Weight_introduce);
        String tip="Body weight refers to the weight of the body. In addition to the close relationship with bone growth, weight gain is also related to the growth of muscle and fat.";
        infofly_tip1_tv.setText(tip);

        //执行了这一句 下面的UpdateCurrentMesureInfo接口会回调display方法
        if (getParentFragment()!=null){
            ((Info_Fragment)getParentFragment()).getCurrentDisplayInfo(TAG);
        }


    }





    private void display(SeneoUserinfos currentUserinfos) {
        if (info_levelview==null||currentUserinfos==null)return;

        dealMiddleValue(currentUserinfos);

        int unit = SeneoUtils.getUnitModel();




        if (unit==0){//kg
            info_levelview.setDisInfo(middleKg,colors,buttoms);
            info_levelview.setMinMaxValuse(IUserContant.IDIS.unitkg_min, IUserContant.IDIS.unitkg_max);
            info_levelview.setDrawWujiaoxin((currentUserinfos.currentWeight==0?false:true));
            info_levelview.displayValue(currentUserinfos.currentWeight);

            ViewUtils.setTextViewStr(infofly_value_tv, NumUtils.numBaoLiuWei1(currentUserinfos.currentWeight)+"");
            ViewUtils.setTextViewStr(infofly_valueunit_tv, IUserContant.IDIS.kg);
        }else {//lb
            info_levelview.setDisInfo(middleLb,colors,buttoms);
            info_levelview.setMinMaxValuse(IUserContant.IDIS.unitlb_min, IUserContant.IDIS.unitlb_max);
            float lbWeight =SeneoUtils.kg2lb(currentUserinfos.currentWeight);
            info_levelview.setDrawWujiaoxin((currentUserinfos.currentWeight==0?false:true));

            info_levelview.displayValue(lbWeight);
            ViewUtils.setTextViewStr(infofly_value_tv, NumUtils.numBaoLiuWei1(lbWeight)+"");
            ViewUtils.setTextViewStr(infofly_valueunit_tv, IUserContant.IDIS.lb);
        }

        //最后修改一下 如果体重是为零就显示横杠
        if (currentUserinfos.currentWeight==0){
            ViewUtils.setTextViewStr(infofly_value_tv, IUserContant.IDIS.Non);
        }



    }








    @Override
    public void UpdateCurrentMesureInfo(SeneoUserinfos currentUserinfos, SeneoUserCurrentMeasureRecord currentMeasureRecord) {
        display(currentUserinfos);
    }
}
